﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Entity;
using System.Data;
using ClassLibrary.Data;

namespace ClassLibrary.DAO
{
    public class TblShipToDAO
    {
        private DBService _db = null;
        public TblShipToDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public TblShipTo GetAll(int AccountID)
        {
            TblShipTo shippto = new TblShipTo();
            try
            {
                DataTable dt = _db.ExeSP_DataTable("select * from TblShipTo where AccountID = @AccountID ",
                   new string[] { "@AccountID" },
                   new object[] { AccountID },
                  CommandType.Text);

                foreach (DataRow dr in dt.Rows)
                {
                    shippto.AccountID = AccountID;
                    shippto.FullName = dr["FullName"].ToString();
                    shippto.Address = dr["Address"].ToString();
                  
                    shippto.Suburb = dr["Suburb"].ToString();
                    shippto.State = dr["State"].ToString();
                    shippto.PostCode = dr["PostCode"].ToString();

                    shippto.HomePhone = dr["HomePhone"].ToString();
                    shippto.MobilePhone = dr["MobilePhone"].ToString();
                    
                    shippto.Country = dr["Country"].ToString();
                    shippto.Email = dr["Email"].ToString();

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return shippto;
        }


        public bool Update(TblShipTo shipto)
        {
            bool flag = false;
            try
            {
                int result = 0;
                result = _db.ExeSP_NonQuery("[sp_ShippingTo_Upd]",
                    new string[] { "@p_AccountID", "@p_Name", "@p_Address", "@p_Suburb", "@p_State", "@p_Country", "@p_ZipCode", "@p_MobilePhone", "@p_HomePhone", "@p_Email" },
                    new object[] { shipto.AccountID, shipto.FullName, shipto.Address, shipto.Suburb, shipto.State, shipto.Country, shipto.PostCode, shipto.MobilePhone, shipto.HomePhone, shipto.Email},
                    CommandType.StoredProcedure);

                flag = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
    }
}
